import sys
# 进度条
import time


class ProgressBar:
    def __init__(self, count=0, total=0, width=100):
        self.count = count
        self.total = total
        self.width = width

    def move(self):
        self.count += 1

        sys.stdout.write(' ' * (self.width + 9) + '\r')  #
        sys.stdout.flush()
        # print(s)
        progress = self.width * self.count // self.total
        sys.stdout.write('{0}/{1}: '.format(self.count, self.total))
        sys.stdout.write('#' * progress + '-' * (self.width - progress) + '\r')
        # if progress == self.width:
        #     sys.stdout.write('\n')
        sys.stdout.flush()

    def log(self, s):
        sys.stdout.write(' ' * (self.width + 9) + '\r')  #
        sys.stdout.flush()
        # print(s)
        progress = self.width * self.count // self.total
        sys.stdout.write('{0}/{1}: '.format(self.count, self.total))
        sys.stdout.write('#' * progress + '-' * (self.width - progress) + '\r')
        if progress == self.width:
            sys.stdout.write('\n')
        sys.stdout.flush()


if __name__ == "__main__":
    bar = ProgressBar(total=300)
    for i in range(300):
        bar.move()
        bar.log()
        # bar.log('We have arrived at: ' + str(i + 1))
        time.sleep(0.01)
